package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class Adressebog here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Adressebog
{
    // instance variables - replace the example below with your own
    public static ArrayList<Person> persons;
    /**
     * Constructor for objects of class Adressebog
     */
    public Adressebog()
    {
        persons = new ArrayList<Person>(); // Create arraylist
    }
    
    public void addPerson(Person person)
    {
        persons.add(person);
    }
    
    public void printAdressBook()
    {
        System.out.println("Adressbook listing: ");

        for(Person person : persons) {
            System.out.println(person.printname());
        }
    }
    
    public void sletPerson(Person person)
    {
        persons.remove(person);
    }
    
    public void findPerson(String name) 
    {
        for(Person person : persons) {
            if(person.printname() == name) {
                System.out.println("Navn: " + person.printname());
                System.out.println("Adresse: " + person.printAdresse());
                System.out.println("Telefon: " + person.printTlfnr());
            } else {
                System.out.println("# Fejl: " + name + "findes ikke.");            }
        }
    }

    public void opdaterPerson(String nowName, String newname, String newEName, String newAddress, String newTlfNr)     {
        for(Person person : persons) {
            if(person.printname() == nowName) {                    person.name = newname; // Changes the forname of the person with the name equals nowName                    person.adresse = newAddress; // Changes the address of the person with the name equals nowName
                    person.tlfnr = newTlfNr; // Changes the phonenumber of the person with the name equals nowName

            }
        }
    }
    
}